/**
 * @file poj/1961/main
 * @brief 给定一个长度为 n 的字符串 s，求它每个前缀的最短循环节
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/6/18 21:32:18
 **/

#include <iostream>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = 1000000 + 10;
char P[N];
int f[N];
int main() {
  // High rating and good luck!
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, kase = 0;
  while (cin >> n && n) {
    cin >> P;
    f[0] = f[1] = 0;  // 递推初始值
    for (int i = 1; i < n; ++i) {
      int j = f[i];
      while (j && P[i] != P[j]) j = f[j];     // KMP 预处理 next 数组
      f[i + 1] = (P[i] == P[j] ? j + 1 : 0);  // TODO: 这一句什么意思？
    }
    // f[] 中保存了前 i 个字符组成的的循环节的长度
    cout << "Test case #" << ++kase << '\n';
    for (int i = 2; i <= n; ++i)
      if (f[i] > 0 && i % (i - f[i]) == 0)  // 能够表示成前缀的重复
        cout << i << ' ' << i / (i - f[i]) << '\n';
    cout << '\n';
  }
  return 0;
}
